package redis

import (
	gredis "github.com/garyburd/redigo/redis"
)

//HSET key field value
//Return Value
/*
1 if field is a new field in the hash and value was set.
0 if field already exists in the hash and the value was updated.
*/
func (r *RedisPool) HSet(key interface{}, field interface{}, value interface{}) (int, error) {
	return gredis.Int(r.Do("HSET", key, field, value))
}

//HGET key field
//Return value
/*
Bulk string reply: the value associated with field, or nil when field is not present in the hash or key does not exist
*/
func (r *RedisPool) HGet(key interface{}, field interface{}) (string, error) {
	return gredis.String(r.Do("HGET", key, field))
}

//HGETALL key
//Return value
/*
Array reply: list of fields and their values stored in the hash, or an empty list when key does not exist.
*/
func (r *RedisPool) HGetAll(key interface{}) (map[string]string, error) {
	return gredis.StringMap(r.Do("HGETALL", key))
}

//HEXISTS key field
// Return value
/*
Integer reply, specifically:
1 if the hash contains field.
0 if the hash does not contain field, or key does not exist.
*/
func (r *RedisPool) HExists(key interface{}, field interface{}) (bool, error) {
	return gredis.Bool(r.Do("HEXISTS", key, field))
}

//HDEL key field [field ...]
//Return value
/*
Integer reply: the number of fields that were removed from the hash, not including specified but non existing fields.
*/
func (r *RedisPool) HDel(key interface{}, field interface{}, fields ...interface{}) (int, error) {
	var tmp []interface{}
	tmp = append(tmp, key, field)
	tmp = append(tmp, fields...)
	return gredis.Int(r.Do("HDEL", tmp...))
}

//HMGET key field [field ...]
//Return value
/*
Array reply: list of values associated with the given fields, in the same order as they are requested.
*/
func (r *RedisPool) HMGet(key interface{}, field interface{}, fields ...interface{}) ([]string, error) {
	var tmp []interface{}
	tmp = append(tmp, key, field)
	tmp = append(tmp, fields...)
	return gredis.Strings(r.Do("HMGET", tmp...))
}

//HMSET key field value [field value ...]
//Return value
/*
Simple string reply
*/
func (r *RedisPool) HMSet(key interface{}, field interface{}, args ...interface{}) (string, error) {
	var tmp []interface{}
	tmp = append(tmp, key, field)
	tmp = append(tmp, args...)
	return gredis.String(r.Do("HMSET", tmp...))
}

//HINCRBY key field increment
//Return value
/*
integer reply: the value at field after the increment operation
*/
func (r *RedisPool) HIncrBy(key interface{}, field interface{}, increment interface{}) (int64, error) {
	return gredis.Int64(r.Do("HINCRBY", key, field, increment))
}

//HINCRBYFLOAT key field increment
//Return value
/*
bulk string reply: the value at field after the increment operation
*/
func (r *RedisPool) HIncrByFloat(key interface{}, field interface{}, increment interface{}) (string, error) {
	return gredis.String(r.Do("HINCRBYFLOAT", key, field, increment))
}

//HKEYS key
//return value
/*
Array reply: list of fields in the hash, or an empty list when key does not exist
*/
func (r *RedisPool) HKeys(key interface{}) ([]string, error) {
	return gredis.Strings(r.Do("HKEYS", key))
}

//HLEN key
//return value
/*
Integer reply: number of fields in the hash, or 0 when key does not exist.
*/
func (r *RedisPool) HLen(key interface{}) (int64, error) {
	return gredis.Int64(r.Do("HLEN", key))
}

//HSETNX key field value
//return value
/*
integer reply, specifically
1 if field is a new field in the hash and value was set
0 if field already exists in the hash and no operation was performed
*/
func (r *RedisPool) HSetNX(key, field, value interface{}) (int, error) {
	return gredis.Int(r.Do("HSETNX", key, field, value))
}

//HSTRLEN key field
//return value
/*
Integer reply:the string length of the value associated with field,
			  or zero when fields is not present in the hash or key does not exist at all
*/
func (r *RedisPool) HStrLen(key, field interface{}) (int64, error) {
	return gredis.Int64(r.Do("HSTRLEN", key, field))
}

//HVALS key
//return value
/*
Array reply: list of values in the hash,or an empty list when key does not exist
*/
func (r *RedisPool) HVals(key interface{}) ([]string, error) {
	return gredis.Strings(r.Do("HVALS", key))
}
